Toggle + callback

Hello,

I would like to have the toggle automatically deselect when another option is choosen, so far the examples I have looked at have not worked what am I doing wrong? Any help would be appreciated. Thank you.

-Jim
 

int  checkbox()
{
    int checked = 0
        
        if (get(templateAltranDBE))
        {checked++}
        if (get(templateWINDBE))
        {checked++}
        if (get(templateEPDBE))
        {checked++}
        if (get(templatePPMDBE))
        {checked++}
        
        set(templateAltranDBE, false)
        set(templateWINDBE, false)
        set(templateEPDBE, false)
        set(templatePPMDBE, false)
        
        return (checked)
}
 
void main(DB win)
{
        if (checkbox() < 2)
        {
                if (get(templateAltranDBE))
                {BodyTemplate = "??"}
                else if (get(templateWINDBE))
                {BodyTemplate = "??"}
                else if (get(templateEPDBE))
                {BodyTemplate = "??"}
                else if (get(templatePPMDBE))
                {BodyTemplate = "??"}
                else
                {BodyTemplate = "??"}
                        
                simpleRpePublish(current Module)
        }
        else{ack "Only one template can be checked!"}
}
 
void createDB ()
{    
        FMod = field(createLS, "Module:",fullName(current Module), 65, false)
        
    templateAltranDBE = toggle(createLS, "??.dta", false)
    templateAltranDBE -> "top" -> "flush"
    templateAltranDBE -> "left" -> "aligned"
        
    templateWINDBE = toggle(createLS, "??.dta", false)
    templateWINDBE -> "top" -> "aligned" -> templateAltranDBE
    templateWINDBE -> "left" -> "flush" -> templateAltranDBE
 
    templateEPDBE = toggle(createLS, "??.dta", false)
    templateEPDBE -> "top" -> "aligned" -> templateWINDBE
    templateEPDBE -> "left" -> "flush" -> templateWINDBE
        
    templatePPMDBE = toggle(createLS, "??.dta", false)
    templatePPMDBE -> "top" -> "aligned" -> templateEPDBE
    templatePPMDBE -> "left" -> "flush" -> templateEPDBE
 
        apply (createLS, "OK", main)
        realize (createLS)
        show (createLS)
}

SystemAdmin - Wed Mar 21 12:06:13 EDT 2012

Re: Toggle + callback
llandale - Wed Mar 21 12:58:08 EDT 2012

You assign a "callback" function to fire when the target DBE changes. In the following, take notice that the DBEs are defined globally before the rest of the code; not sure how else the callback can realistically get a handle on dbe2.

DB     db
DBE     dbe1, dbe2
 
void    clbkDisable(DBE dbeXX)
{
        bool    Disable = get(dbe1)
        if (Disable)
        {  set(dbe2, false)
           inactive(dbe2)
        }
        else
        {  active(dbe2)
        }
}     // end clbkDisable()
 
db      = create("Toggle")
dbe1    = toggle(db, "Disable Options", true)
dbe2    = toggle(db, "Options", true)
 
set(dbe1, clbkDisable)  // Fire the callback when dbe1 changes
clbkDisable(dbe1)               // Invoke it now 
 
show(db)


-Louie

Re: Toggle + callback
SystemAdmin - Wed Mar 21 20:31:33 EDT 2012

llandale - Wed Mar 21 12:58:08 EDT 2012

You assign a "callback" function to fire when the target DBE changes. In the following, take notice that the DBEs are defined globally before the rest of the code; not sure how else the callback can realistically get a handle on dbe2.

DB     db
DBE     dbe1, dbe2
 
void    clbkDisable(DBE dbeXX)
{
        bool    Disable = get(dbe1)
        if (Disable)
        {  set(dbe2, false)
           inactive(dbe2)
        }
        else
        {  active(dbe2)
        }
}     // end clbkDisable()
 
db      = create("Toggle")
dbe1    = toggle(db, "Disable Options", true)
dbe2    = toggle(db, "Options", true)
 
set(dbe1, clbkDisable)  // Fire the callback when dbe1 changes
clbkDisable(dbe1)               // Invoke it now 
 
show(db)


-Louie

Thank you. That example really helped.

-Jim